package com.xbongbong.pro.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.saas.enums.business.PurchaseInvoiceEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * 打印 发票
 *
 * @author 徐俊杰
 * @date 2019/12/3 10:22
 * @since v1.0
 */
@Getter
public enum PrintInvoicePurchaseTotalMoneyEnum {

    /**
     * 关联采购合同
     */
    PURCHASE(PurchaseInvoiceEnum.PURCHASE_ID.getAttr(), PurchaseInvoiceEnum.PURCHASE_ID.getI18nAttrName(),0),
    /**
     * 关联付款
     */
    PAY_PLAN(PurchaseInvoiceEnum.PAY_PLAN_ID.getAttr(), "enum.printinvoicepurchasetotalmoney.name.pay_plan", 1),
    /**
     * 开票金额
     */
    TOTAL_MONEY(PurchaseInvoiceEnum.TOTAL_MONEY.getAttr(), PurchaseInvoiceEnum.TOTAL_MONEY.getI18nAttrName(),2),
    ;
    private String attr;
    private String name;
    private int sort;

    PrintInvoicePurchaseTotalMoneyEnum(String attr, String name, int sort) {
        this.attr = attr;
        this.name = name;
        this.sort = sort;
    }


    public static List<PrintInvoicePurchaseTotalMoneyEnum> getAllEnum() {
        List<PrintInvoicePurchaseTotalMoneyEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static PrintInvoicePurchaseTotalMoneyEnum getByAttr(String alias) {
        for (PrintInvoicePurchaseTotalMoneyEnum cacheCode : values()) {
            if (cacheCode.getAttr().equals(alias)) {
                return cacheCode;
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
